#pragma once


namespace util
{

	template <class T, uint Alignment>
	class AlignedMemAlloc 
	{

	public:
		typedef size_t    size_type;
		typedef ptrdiff_t difference_type;
		typedef T*        pointer;
		typedef const T*  const_pointer;
		typedef T&        reference;
		typedef const T&  const_reference;
		typedef T         value_type;

		template <class U>
		struct rebind
		{
			typedef AlignedMemAlloc<U, Alignment> other;
		};

		pointer address (reference value) const 
		{
			return &value;
		};

		const_pointer address (const_reference value) const 
		{
			return &value;
		};

		AlignedMemAlloc() throw() 
		{
		}

		AlignedMemAlloc(const AlignedMemAlloc &) throw() 
		{
		}

		template <class U, uint ALIGN>
		AlignedMemAlloc(const AlignedMemAlloc<U, ALIGN> &) throw() 
		{
		}

		~AlignedMemAlloc() throw() 
		{
		}

		size_type max_size () const throw() 
		{
			return 268435455;
		};

		pointer allocate (size_type num, const_pointer * hint = 0) 
		{
			return (pointer) _aligned_malloc(num * sizeof(T), Alignment);
			//return (pointer) malloc(num * sizeof(T));
		};


		void construct (pointer p, const T& value) 
		{
			// memcpy( p, &value, sizeof T );
			*p=value;
			//  new ( (void *) p ) T ( value );
		};

		void destroy (pointer p) 
		{
			p->~T();
		};

		void deallocate (pointer p, size_type num) 
		{
			_aligned_free( p );
			//free(p);
		};
	};

}